package copyengine.sceneAndDialog.scene
{
    import copyengine.utils.CEStarlingUtils;

    import starling.display.DisplayObjectContainer;
    import starling.display.Sprite;

    public class CESceneManger
    {
        private static var mInstance:CESceneManger;

        public static function get instance():CESceneManger
        {
            if (mInstance == null) {
                mInstance = new CESceneManger();
            }
            return mInstance;
        }

        private var mCurrentScene:ICEScene;
        private var mSceneMangerContainer:Sprite;

        public function CESceneManger()
        {
            mSceneMangerContainer = new Sprite();
        }

        public function get currentScene():ICEScene {return mCurrentScene}

        public function get sceneMangerContainer():DisplayObjectContainer {return mSceneMangerContainer;}

        public function changeScene(_newScene:ICEScene):void
        {
            if (mCurrentScene != null) {
                CEStarlingUtils.removeTargetFromParent(mCurrentScene.sceneContainer);
                mCurrentScene.dispose();
            }
            mCurrentScene = _newScene;
            mSceneMangerContainer.addChild(mCurrentScene.sceneContainer);
            mCurrentScene.onAddToSceneManger();
        }

    }
}
